// pages/My/Recharge/Recharge.js
var url = wx.getStorageSync('url') 
var shopid = wx.getStorageSync('shopid') 
var openid = wx.getStorageSync('openid')
var userId = wx.getStorageSync('userId')
var time_ss = wx.getStorageSync('time_ss')

time_ss
Page({

  /**
   * 页面的初始数据
   */
  data: {
      list_1:[{
        message:'50',
        list:'售价：50.00元'
      },{
          message: '100',
          list: '售价：100.00元'
      },{
          message: '200',
          list: '售价：200.00元'
      },{
          message: '500',
          list: '售价：500.00元'
      },{
          message: '1000',
          list: '售价：1000.00元'
      },{
          message: '自定义金额',
          list: '请输入您充值的金额'
      }],
    cen_5s:false,
    value:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(openid)
    var that = this
    var shopid = wx.getStorageSync('shopid')
    var userId = wx.getStorageSync('userId')
    var openid = wx.getStorageSync('openid')
    var time_ss = wx.getStorageSync('time_ss')
    wx.request({
      url: url + 'gateWare/mpUserCenter',
      data: {
        "list": false,
        "nodeId": "kdslfw",
        "platform": 2,
        "privId": "default",
        "resId": "default",
        "sendTime": time_ss,
        "seq": 1,
        "shopId": shopid,
        "source": 11,
        "sysVer": "1.0.0",
        "token": "kdsjfoewi12ijsldks",
        "type": 1,
        "userId": userId,
        "userType": 1,
        "content": {
          "userId": userId,
          "shopId": shopid
        }
      },
      method: "POST",
      header: { "Content-Type": "application/JSON" },
      success: function (e) {
        var data = e.data.content
        console.log(data)
        that.setData({
          banler: data
        })
      }
    })
  },
  quxiao_:function(e){
    var that = this
    that.setData({
      cen_5s: false,
      value:''
    })
  },
  shuru_:function(e){
    var that = this
    var i = e.detail.value
    that.setData({
      value: e.detail.value
    })
  },
  swichNav:function(e){
    var shopid = wx.getStorageSync('shopid')
    var userId = wx.getStorageSync('userId')
    var openid = wx.getStorageSync('openid')
    var time_ss = wx.getStorageSync('time_ss')
    var that = this;
    var k = e.currentTarget.dataset.value*100;
    var re = /^[1-9]+.?[0-9]*/;//判断字符串是否为数字//判断正整数/[1−9]+[0−9]∗]∗/ 
    if(k == ''){
      wx.showToast({
        title: '输入充值金额',
        icon: 'loading',
        duration: 1000
      })
    }
    that.setData({
      currentTab: e.currentTarget.dataset.current,
      currentTab1: e.currentTarget.dataset.current
    })    
    if (!re.test(k)) {
      that.setData({
        cen_5s: true
      })
    } else {
      //  发起支付调用微信支付api
      wx.request({
        url: url + 'gateCash/rechargeStart',
        data: {
          "list": false,
          "nodeId": "kdslfw",
          "platform": 2,
          "privId": "default",
          "resId": "default",
          "sendTime": time_ss,
          "seq": 1,
          "shopId": shopid,
          "source": 11,
          "sysVer": "1.0.0",
          "token": "kdsjfoewi12ijsldks",
          "type": 1,
          "userId": userId,
          "userType": 1,
          "content": {
            "shopId": shopid,
            "openId": openid,
            "appId": "wx6ca4bda138687ed8",
            "balance": k
          }
        },
        method: "POST",
        header: { "Content-Type": "application/JSON" },
        success: function (e) {
         console.log(e.data.content)
          var i = e.data.content
          wx.requestPayment({
            timeStamp: i.timeStamp,
            nonceStr: i.nonce_str,
            package: 'prepay_id='+i.prepay_id,
            signType: 'MD5',
            paySign: i.paySign,
            success(res) {
              that.setData({
                cen_5s: false,
                value: ''
              })
              wx.request({
                url: url + 'gateCash/rechargeSuccess',
                data: {
                  "list": false,
                  "nodeId": "kdslfw",
                  "platform": 2,
                  "privId": "default",
                  "resId": "default",
                  "sendTime": time_ss,
                  "seq": 1,
                  "shopId": shopid,
                  "source": 11,
                  "sysVer": "1.0.0",
                  "token": "kdsjfoewi12ijsldks",
                  "type": 1,
                  "userId": userId,
                  "userType": 1,
                  "content": {
                    "tradeId": i.tradeId
                  },
                  "page": 1,
                  "limit": 15
                },
                method: "POST",
                header: { "Content-Type": "application/JSON" },
                success: function (e) {
                 
                  wx.request({
                    url: url + 'gateWare/mpUserCenter',
                    data: {
                      "list": false,
                      "nodeId": "kdslfw",
                      "platform": 2,
                      "privId": "default",
                      "resId": "default",
                      "sendTime": time_ss,
                      "seq": 1,
                      "shopId": shopid,
                      "source": 11,
                      "sysVer": "1.0.0",
                      "token": "kdsjfoewi12ijsldks",
                      "type": 1,
                      "userId": userId,
                      "userType": 1,
                      "content": {
                        "userId": userId,
                        "shopId": shopid
                      }
                    },
                    method: "POST",
                    header: { "Content-Type": "application/JSON" },
                    success: function (e) {
                      var data = e.data.content
                      console.log(data)
                      that.setData({
                        banler: data
                      })
                    }
                  })
                }
              })
             },
            fail(res) { 
              console.log(res)
            }
          })
        }
      })
    } 
    　　
      
  },

  goto_Record:function(){
    wx.navigateTo({
      url: 'Record/Record',
      success: function(res) {},
      fail: function(res) {},
      complete: function(res) {},
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})